package com.erytech.linktalk.web.client.dataview;

import com.erytech.linktalk.web.client.datasource.PortraitDataSource;
import com.erytech.linktalk.web.client.framework.DataUpdateEvent;
import com.erytech.linktalk.web.client.framework.PopupDataView;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.SourcesTableEvents;
import com.google.gwt.user.client.ui.TableListener;

public class PortraitView extends PopupDataView {

	FlexTable iconsTable = new FlexTable();

	public PortraitView(PortraitDataSource portraitDataSource) {
		super(portraitDataSource);
		initView();
	}

	private void initView() {
		setStyleName("portrait-view");
		for (int row = 0; row < getPortraitDataSource().getRowCount(); row++) {
			for (int col = 0; col < getPortraitDataSource().getColCount(); col++) {
				iconsTable.setWidget(row, col, getPortraitDataSource().getPortraint(row, col));
			}
		}
		iconsTable.addTableListener(new TableListener() {
			public void onCellClicked(SourcesTableEvents sender, int row, int col) {
				PortraitView.this.hide();
				getPortraitDataSource().setSelected(row, col);
			}
		});
		add(iconsTable);
	}

	private PortraitDataSource getPortraitDataSource() {
		return (PortraitDataSource)getDataSource();
	}
	
	public void onDataUpdateEvent(DataUpdateEvent event) {
		//nothing to do.
	}

}